$(function() {

});

function submitOrder(id) {

    var flag = $("#flag option:selected").val();
    var commodityCode = $("#" + id + "_storageCommodityCode").text();
    var commodityName = $("#" + id +  "_storageCommodityName").text();
    var storageMoney = $("#" + id +  "_storageMoney").text();
    var accountUserId = $("#" + id +  "_accountUserId").text();

    if ( commodityCode == undefined || commodityCode == ''){
        alert("commodityCode不能为空！");
        return;
    }

    if ( commodityName == undefined || commodityName == ''){
        alert("commodityName不能为空！");
        return;
    }

    if ( storageMoney == undefined || storageMoney == ''){
        alert("storageMoney不能为空！");
        return;
    }

    if ( accountUserId == undefined || accountUserId == ''){
        alert("storageMoney不能为空！");
        return;
    }
    var business = {
        userId: accountUserId,
        commodityCode : commodityCode,
        commodityName : commodityName,
        count : 1,
        money : storageMoney,
        flag : flag
    };

    $.ajax({
        url: '/business/submitOrder',
        type:'POST',
        data:JSON.stringify(business),
        dataType:'json',
        contentType: 'application/json;charset=UTF-8',
        success:function (data) {
            //后台返回数据就在data里面
            if(data.success){
                window.open("/business/show","_self")
            }else {
                alert(JSON.stringify(data))
            }
        },

    });
}